package de.distmlp.preprocessing.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import de.distmlp.preprocessing.data.MLDataEntry;
import de.distmlp.preprocessing.nlp.dictionary.Dictionary;

/**
 * Maps input to output to train the identity with autoencoder.
 * 
 * @author twist
 * 
 */
public class XingParser_Identity extends XingParser {

	public XingParser_Identity(final Dictionary dictionary, final int nbInputUnits, final int nbOutputUnits) {
		super(dictionary, nbInputUnits, nbOutputUnits);
	}

	@Override
	public List<MLDataEntry> parse(final String input) {
		final List<MLDataEntry> trainingsSet = new ArrayList<MLDataEntry>();

		final Map<String, Integer> dicMap = this.dictionary.getDictionary();
		final String[] lineSplit = input.split(",");
		int count = 0;

		// Dictionary does not contain all lemmas. We need to check
		// if lemma exists in dictionary,

		final MLDataEntry trainingsData = new MLDataEntry(this.nbInputUnits, this.nbOutputUnits);

		if (lineSplit.length > 1) {
			for (final String element : lineSplit) {
				if (dicMap.containsKey(element)) {
					trainingsData.addInput(dicMap.get(element), 1);
					trainingsData.addOutput(dicMap.get(element), 1);
					count++;
				} else {
					continue;
				}
			}
		}
		if (count > 1) {
			trainingsSet.add(trainingsData);
		}

		return trainingsSet;
	}

}
